home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Champak 29
/
Volume 29 - JOGO DISK .iso
/
Games
/
jungle_adventure.swf
/
scripts
/
__Packages
/
SSWorld.as
< prev
next >
Wrap
Text File
|
2006-11-29
|
9KB
|
312 lines
class SSWorld extends GDK.World
{
static var viewportClass = GameViewport;
var useDefaultCamera = false;
var updateID = 0;
var time = 0;
var levelLeft = 0;
var levelTop = 0;
var levelRight = 0;
var levelBottom = 0;
var leftSector = 0;
var rightSector = 0;
var topSector = 0;
var bottomSector = 0;
var sectorsWide = 0;
var sectorsTotal = 0;
var soundsCreated = 0;
var normalVolume = 100;
var muteVolume = 0;
function SSWorld(name, viewport)
{
super();
this.sectors = {};
this.players = [];
if(name)
{
this.name = name;
}
this.viewport = new SSWorld.viewportClass();
this.backgrounds = new GDK.Collection();
this.collections = {};
}
function addToCollection(name, obj)
{
var _loc3_ = this.collections[name];
if(!_loc3_)
{
var _loc0_ = null;
_loc3_ = this.collections[name] = [obj];
}
else
{
var _loc2_ = _loc3_.length;
while((_loc2_ = _loc2_ - 1) > -1)
{
if(_loc3_[_loc2_] == obj)
{
return undefined;
}
}
_loc3_.push(obj);
}
}
function removeFromCollection(name, obj)
{
var _loc3_ = undefined;
var _loc2_ = _loc3_ = this.collections[name].length;
while((_loc2_ = _loc2_ - 1) > -1)
{
if(_loc3_[_loc2_] == obj)
{
_loc3_.splice(_loc2_,1);
}
}
}
function addBackground(bg)
{
bg.world = bg.parent = this;
bg.displayNode = this.target;
bg.uniqueID = ++this.objectsAdded;
this.backgrounds.addMember(bg);
}
function update(elapsed)
{
this.tick = Math.floor(this.time) != Math.floor(this.time += elapsed);
var _loc2_ = this.players.length;
while((_loc2_ = _loc2_ - 1) > -1)
{
this.players[_loc2_].update(elapsed);
}
this.sendEvent("update",elapsed);
this.updateViewport(elapsed);
if(this.viewport.sectorChanged)
{
this.cleanScene();
}
this.render(elapsed);
}
function cleanScene()
{
var _loc6_ = [];
this.viewport.sectorChanged = false;
var _loc7_ = this.sectorsWide;
var _loc3_ = undefined;
var _loc10_ = this.sectorsTotal;
while((_loc10_ = _loc10_ - 1) > -1)
{
if(_loc3_ = this.sectors[this.leftSector + _loc10_ % _loc7_][this.topSector + Math.floor(_loc10_ / _loc7_)])
{
_loc3_._s = -1;
_loc6_.push(_loc3_);
}
}
var _loc0_ = null;
var _loc0_ = null;
_loc10_ = this.sectorsTotal = (_loc7_ = this.sectorsWide = (this.rightSector = this.viewport.rightSector) - (this.leftSector = this.viewport.leftSector)) * ((this.bottomSector = this.viewport.bottomSector) - (this.topSector = this.viewport.topSector));
while((_loc10_ = _loc10_ - 1) > -1)
{
if(_loc3_ = this.sectors[this.leftSector + _loc10_ % _loc7_][this.topSector + Math.floor(_loc10_ / _loc7_)])
{
if(!_loc3_._s)
{
_loc3_._s = 1;
_loc6_.push(_loc3_);
}
else
{
_loc3_._s = 0;
}
}
}
_loc10_ = _loc6_.length;
var _loc9_ = [];
var _loc4_ = undefined;
var _loc2_ = undefined;
var _loc8_ = undefined;
var _loc5_ = undefined;
while((_loc10_ = _loc10_ - 1) > -1)
{
_loc5_ = _loc8_ = _loc6_[_loc10_].length;
_loc4_ = _loc8_._s;
while((_loc5_ = _loc5_ - 1) > -1)
{
if(_loc2_ = _loc8_[_loc5_]._s == null)
{
_loc2_._s = _loc4_;
_loc9_.push(_loc2_);
}
else if(_loc4_ > _loc2_._s)
{
_loc2_._s = _loc4_;
}
}
delete _loc6_[_loc10_]._s;
}
_loc10_ = _loc9_.length;
while((_loc10_ = _loc10_ - 1) > -1)
{
_loc2_ = _loc9_[_loc10_];
if(_loc2_._s < 0)
{
_loc2_.removeFromScene();
}
else if(_loc2_._s > 0)
{
_loc2_.addToScene();
}
delete _loc2_._s;
}
}
function render(elapsed)
{
if(!this.displayQueue.length)
{
return undefined;
}
if(this.viewport.changed)
{
this.target._x = Math.floor(- this.viewport.x);
this.target._y = Math.floor(- this.viewport.y);
var _loc2_ = this.backgrounds.length;
while((_loc2_ = _loc2_ - 1) > -1)
{
this.backgrounds[_loc2_].setDisplay(this.viewport);
}
}
var _loc3_ = this.viewport.wTan * 1 / this.viewport.focusDepth;
_loc2_ = this.displayQueue.length;
while((_loc2_ = _loc2_ - 1) > -1)
{
this.displayQueue[_loc2_].setDisplay(this.viewport,elapsed,_loc3_);
delete this.displayQueue[_loc2_].queueForDisplay;
}
this.displayQueue = [];
this.viewport.changed = false;
updateAfterEvent();
}
function getSectors(l, t, r, b)
{
var _loc6_ = this.sectors;
var _loc3_ = undefined;
var _loc2_ = (_loc3_ = r - l + 1) * (b - t + 1);
var _loc4_ = undefined;
r = [];
while((_loc2_ = _loc2_ - 1) > -1)
{
if(_loc4_ = _loc6_[l + _loc2_ % _loc3_][t + Math.floor(_loc2_ / _loc3_)])
{
r.push(_loc4_);
}
}
return r;
}
function getObjectsInSectors(l, t, r, b)
{
var _loc6_ = this.sectors;
var _loc4_ = undefined;
var _loc2_ = (_loc4_ = r - l + 1) * (b - t + 1);
var _loc5_ = undefined;
var _loc3_ = [];
while((_loc2_ = _loc2_ - 1) > -1)
{
if(_loc5_ = _loc6_[l + _loc2_ % _loc4_][t + Math.floor(_loc2_ / _loc4_)])
{
_loc3_ = _loc3_.concat(_loc5_);
}
}
return _loc3_;
}
function updateViewport(elapsed)
{
this.viewport.update(elapsed);
}
function onAddToScene()
{
this.target._visible = true;
this.viewport.screenWidth = this.engine.width;
this.viewport.screenHeight = this.engine.height;
this.viewport.world = this;
this.viewport.onAddToWorld();
var _loc2_ = this.backgrounds.length;
while((_loc2_ = _loc2_ - 1) > -1)
{
this.backgrounds[_loc2_].addDisplay();
this.backgrounds[_loc2_].setDisplay(this.viewport);
}
this.onSSAddToScene();
}
function onAddDisplay()
{
this.soundContainer = this.target.createEmptyMovieClip("SoundContainer",-1200);
this.soundObject = new Sound(this.soundContainer);
this.initSound();
}
function removeFromScene()
{
this.target._visible = false;
this.inScene = false;
for(var _loc2_ in this.soundContainer)
{
this.soundContainer[_loc2_].sound.stop();
}
}
function createSound(id, linkageID)
{
if(linkageID != null)
{
var _loc2_ = this.soundContainer.attachMovie(linkageID,id,++this.soundsCreated);
}
else
{
_loc2_ = this.soundContainer.createEmptyMovieClip(id,++this.soundsCreated);
}
var _loc3_ = new Sound(_loc2_);
_loc2_.sound = _loc3_;
return _loc2_;
}
function muteSounds()
{
this.soundObject.setVolume(this.muteVolume);
}
function unmuteSounds()
{
this.soundObject.setVolume(this.normalVolume);
}
function deleteSound(id)
{
this.soundContainer[id].sound.stop();
this.soundContainer[id].removeMovieClip();
}
function playEventSound(id, name)
{
if(id.sound)
{
var _loc2_ = id;
}
else
{
_loc2_ = this.soundContainer[id];
}
_loc2_.gotoAndStop(name);
_loc2_.nextFrame();
}
function addPlayer(player)
{
this.players.push(player);
}
function removePlayer(player)
{
var _loc3_ = undefined;
var _loc2_ = _loc3_ = this.players.length;
while((_loc2_ = _loc2_ - 1) > -1)
{
if(_loc3_[_loc2_] == player)
{
_loc3_.splice(_loc2_,1);
break;
}
}
}
}